//
//  SuperviseViewController.m
//  wsgz
//
//  Created by huck on 2017/5/4.
//  Copyright © 2017年 BoingPay. All rights reserved.
//

#import "SuperviseViewController.h"
#import "AppUtils.h"
#import "HomeManager.h"
#import "BMUtils.h"
#import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
#import "SuperviseDetailViewController.h"
//#import "BNCoreServices.h"
#import "UIViewController+Alert.h"
//#import "PhoneGPSViewController.h"

@interface SuperviseViewController ()<BMKMapViewDelegate,BMKLocationServiceDelegate,UITableViewDelegate,UITableViewDataSource>//,BNNaviUIManagerDelegate,BNNaviRoutePlanDelegate>

@property (nonatomic,strong) BMKLocationService *locService; //
@property (nonatomic,assign) BOOL hasLoad; //线的集合
@property (nonatomic,copy) NSString *currentDirtyId;

@property (nonatomic,strong) NSMutableArray *mapAnnotations; //标注的集合
@property (nonatomic,strong) NSMutableArray *mapAnnotationValues; //标注值的集合
@property (nonatomic,strong) NSMutableArray *mapOverlays; //线的集合
@property (nonatomic,strong) NSMutableArray *mapOverlayValues; //线值的集合

@property (nonatomic,strong) NSMutableArray *resultList;
@property (nonatomic,strong) NSMutableArray *resultListIds;//"00"去重
@property (nonatomic,strong) NSMutableArray *linkResultList;//联想输入的列表


//    左上角
@property (nonatomic,assign) CGFloat leftUpLongSave;
@property (nonatomic,assign) CGFloat leftUpLatiSave;
//    右下角
@property (nonatomic,assign) CGFloat rightDownLongSave;
@property (nonatomic,assign) CGFloat rightDownLatiSave;

@end

@implementation SuperviseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initSubview];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [_mapView viewWillAppear];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    _locService.delegate = self;
    [self hideInput];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil
    _locService.delegate = nil;
    [self hideInput];
    [self hideTableView];
}

- (void)dealloc {
    if (_mapView) {
        _mapView = nil;
    }
}

-(void)initSubview
{
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"my_location_icon"] style:UIBarButtonItemStyleDone target:self action:@selector(selectorUserLogin)];
    [AppUtils addBarButton:self image:[UIImage imageNamed:@"my_location_icon"] action:nil position:PositionTypeLeft];
    
    _mapAnnotations = [NSMutableArray array];
    _mapOverlays = [NSMutableArray array];
    _mapAnnotationValues = [NSMutableArray array];
    _mapOverlayValues = [NSMutableArray array];
    _resultList =[NSMutableArray array];
    _resultListIds = [NSMutableArray array];
    _linkResultList = [NSMutableArray array];
    
    _waterInfoView.hidden = YES;
    _waterInfoView.top = MAIN_CONTENT_HEIGHT+20;
    _superviseBtn.hidden = ![LOGIN_USER canSuperView];
    
    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideInputWaterInfo)]];

    //设置地图坐标中心点
    BMKCoordinateRegion regin;
    regin.span = self.mapView.region.span;
    regin.center = [BMUtils getPoint:DEFAULT_LOCATION];
    [_mapView setRegion:regin animated:NO];
    
    //当前位置定位
    _locService = [[BMKLocationService alloc]init];
    //启动LocationService
    [_locService startUserLocationService];
    _mapView.showsUserLocation = NO;//先关闭显示的定位图层
    _mapView.userTrackingMode = BMKUserTrackingModeNone;//设置定位的状态
    _mapView.showsUserLocation = YES;//显示定位图层
}

-(void)locationMyPosition
{
    CLLocationCoordinate2D center = _locService.userLocation.location.coordinate;
    [self locationMyPosition:center];
    [_mapView setCenterCoordinate:center animated:NO];
    _mapView.zoomLevel = DEFAULT_MAP_LEVEL;
}

//定位到自己,并且获取周围的数据
-(void)locationMyPosition:(CLLocationCoordinate2D)center
{
    BMKCoordinateRegion regin = _mapView.region;
    regin.center = center;
    //周围区域
    CGFloat centerLongitude = regin.center.longitude;
    CGFloat centerLatitude = regin.center.latitude;     //当前屏幕显示范围的经纬度
    CLLocationDegrees pointssLongitudeDelta = regin.span.longitudeDelta;
    CLLocationDegrees pointssLatitudeDelta = regin.span.latitudeDelta;
    //    左上角
    CGFloat leftUpLong = centerLongitude - pointssLongitudeDelta/2.0;
    CGFloat leftUpLati = centerLatitude - pointssLatitudeDelta/2.0;
    //    右下角
    CGFloat rightDownLong = centerLongitude + pointssLongitudeDelta/2.0;
    CGFloat rightDownLati = centerLatitude + pointssLatitudeDelta/2.0;
    //判断是否加载
    if(leftUpLong>=_leftUpLongSave && rightDownLong<=_rightDownLongSave && leftUpLati>=_leftUpLatiSave && rightDownLati<=_rightDownLatiSave ){
//        NSLog(@"区域内不加载");
    }else{
        _leftUpLongSave = leftUpLong;
       _leftUpLatiSave = leftUpLati;
        _rightDownLongSave = rightDownLong;
        _rightDownLatiSave = rightDownLati;
        
        NSArray *arr = @[@{@"lng":[NSString stringWithFormat:@"%f",leftUpLong],@"lat":[NSString stringWithFormat:@"%f",leftUpLati]},@{@"lng":[NSString stringWithFormat:@"%f",rightDownLong],@"lat":[NSString stringWithFormat:@"%f",rightDownLati]}];
        [[HomeManager sharedInstance] requestRectWaterDirtyList:arr complete:^(BOOL success) {
            [self updateMapInfo];
        }];
    }
}

//根据水体名称搜索,如果是空的,就定位到自己周围
- (void)searchByName
{
    //获取一连串参数
    NSString *wName = [AppUtils trim:_searchTextField.text];
    
//    if([AppUtils isEmpty:wName]){
//        return;
//    }

    [Toast loading];
    [[HomeManager sharedInstance] requestWaterDirtyList:wName complete:^(BOOL success) {
        [Toast loaded];
        [_linkResultList removeAllObjects];
        for(WaterDirtyData *data in [HomeManager sharedInstance].waterDirtyList){
                if([@"00" isEqualToString:data.position.status]){ //折线水体范围
                    [_linkResultList addObject:data];
                }
        }
        [_linkTableView reloadData];
        [self updateMapInfo];
    }];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [super textFieldShouldReturn:textField];
    [self searchByName];
    return YES;
}

// 用于自定义键盘的移动view （BaseViewController）
- (UIView *)frameRootView
{
    return self.view;
}

-(WaterDirtyData *)getWaterDataById:(NSString *)dirtyId
{
    if([AppUtils isNotEmpty:dirtyId]){
        for(WaterDirtyData *data in _resultList){
            if([dirtyId isEqualToString:data.dirtyId]){
                return data;
            }
        }
    }
    return nil;
}

//地图上更新数据
-(void)updateMapInfo
{
    [_resultList removeAllObjects];
    [_resultListIds removeAllObjects];
    
    int indexValue = 1;
    for(WaterDirtyData *data in [HomeManager sharedInstance].waterDirtyList){
        if(![_resultListIds containsObject:data.dirtyId]){
            if([@"00" isEqualToString:data.position.status]){ //折线水体范围
                data.index = indexValue;
                indexValue ++;
            }
            [_resultListIds addObject:data.dirtyId];
            [_resultList addObject:data];
        }else{
//            NSLog(@"====水体重复了:%@====",data.waterName);
        }
    }
    for(WaterDirtyData *data in [HomeManager sharedInstance].waterMapList){
        if(![_resultListIds containsObject:data.dirtyId]){
            if([@"00" isEqualToString:data.position.status]){ //折线水体范围
                data.index = indexValue;
                indexValue ++;
            }
            [_resultListIds addObject:data.dirtyId];
            [_resultList addObject:data];
        }else{
//            NSLog(@"====水体重复了:%@====",data.waterName);
        }
    }
    [_mapView removeAnnotations:_mapAnnotations];
    [_mapAnnotations removeAllObjects];
    [_mapAnnotationValues removeAllObjects];
    [_mapView removeOverlays:_mapOverlays];
    [_mapOverlays removeAllObjects];
    [_mapOverlayValues removeAllObjects];
    
    if([AppUtils isNotEmptyArray:_resultList]){
        for(WaterDirtyData *item in _resultList){
            if([@"00" isEqualToString:item.position.status]){ //折线水体范围
                NSArray *pointsArr = [item.position.position componentsSeparatedByString:@";"];
                NSMutableArray *points = [NSMutableArray arrayWithArray:[pointsArr copy]];
                [points addObject:pointsArr.firstObject];
                NSMutableArray *colorIndexs = [NSMutableArray array];
                int j = 0;
                
                CLLocationCoordinate2D *coors;
                coors = (CLLocationCoordinate2D *)malloc(points.count*sizeof(CLLocationCoordinate2D));//为结构体分配存储空间
                for(int i=0;i<points.count;i++){
                    NSString *pointStr = points[i];
                    if([BMUtils canMakePoint:pointStr]){
                        coors[i] = [BMUtils getPoint:pointStr];
                        j++;
                        //构建分段颜色索引数组
                        [colorIndexs addObject:[NSNumber numberWithInt:0]];
                    }
                }
                //构建BMKPolyline,使用分段颜色索引，其对应的BMKPolylineView必须设置colors属性
                BMKPolyline *colorfulPolyline = [BMKPolyline polylineWithCoordinates:coors count:j textureIndex:colorIndexs];
                [_mapOverlays addObject:colorfulPolyline];
                [_mapView addOverlays:_mapOverlays];
                [_mapOverlayValues addObject:item.dirtyId];
                
                //水体位置加图标
                BMKPointAnnotation * pointAnnotation = [[BMKPointAnnotation alloc] init];
                pointAnnotation.coordinate = [BMUtils getPoint:item.mapTag];
//                pointAnnotation.title = item.waterName;
                [_mapAnnotations addObject:pointAnnotation];
                [_mapAnnotationValues addObject:item.dirtyId];
                
            }else{ //标注排污口
                if([BMUtils canMakePoint:item.position.position]){
                    BMKPointAnnotation * pointAnnotation = [[BMKPointAnnotation alloc] init];
                    pointAnnotation.coordinate = [BMUtils getPoint:item.position.position];
                    pointAnnotation.title = item.position.dirtyName;
                    [_mapAnnotations addObject:pointAnnotation];
                    [_mapAnnotationValues addObject:item.dirtyId];
                }
            }
        }
        
        [_mapView addAnnotations:_mapAnnotations];
    }
}

-(void)textFieldDidChange:(UITextField *)textField
{
    [super textFieldDidChange:textField];
    [self hideTableView];
}

#pragma mark ========[UITableViewDelegate]=======================
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger count =MIN( _linkResultList.count,10);
    _linkTableView.hidden = count==0;
    _linkTableViewH.constant = count*30;
    return count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell =  [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    [btn setTitle:@"" forState:UIControlStateNormal];
    [btn setTitle:@"" forState:UIControlStateHighlighted];
    [btn addTarget:self action:@selector(didSelectRow:) forControlEvents:UIControlEventTouchUpInside];
    btn.tag = 100;
    [cell.contentView addSubview:btn];
    btn = [cell.contentView viewWithTag:100];
    btn.tag = indexPath.row;
    WaterDirtyData *data = [_linkResultList objectAtIndex:indexPath.row];
    cell.textLabel.text = data.waterName;
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.textLabel.textColor = [UIColor colorWithString:COLOR_333333];
    return cell;
}

-(void)didSelectRow:(UIButton *)btn
{
    NSInteger index = btn.tag;
    WaterDirtyData *data = _linkResultList[index];
    _searchTextField.text = data.waterName;
    [self initWaterInfoView:data];
    [self hideTableView];
}

#pragma mark ========地图定位===[BMKLocationServiceDelegate]=======================

/**
 *用户位置更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    if(!_hasLoad){
        [_mapView setCenterCoordinate:userLocation.location.coordinate animated:NO];
        _mapView.zoomLevel = DEFAULT_MAP_LEVEL;
        [self locationMyPosition:userLocation.location.coordinate];
        _hasLoad = YES;
    }
    [_mapView updateLocationData:userLocation];
}


#pragma mark ========地图图层====[BMKMapViewDelegate]======================
- (BMKOverlayView*)mapView:(BMKMapView *)map viewForOverlay:(id<BMKOverlay>)overlay
{
    if ([overlay isKindOfClass:[BMKPolyline class]]) {
        NSInteger index = [_mapOverlays indexOfObject:overlay];
        if(index>=0 && index<_mapOverlayValues.count){
            NSString *dirtyId = [AppUtils toString:_mapOverlayValues[index]];
            WaterDirtyData *data = [self getWaterDataById:dirtyId];
            BMKPolylineView* polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];
            polylineView.lineWidth = 2;
            /// 使用分段颜色绘制时，必须设置（内容必须为UIColor）
            polylineView.colors = @[[AppUtils getQualityClass:data.wTypeName]];
            return polylineView;
        }
    }
    return nil;
}

// 根据anntation生成对应的View
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    //普通annotation
    NSInteger index = [_mapAnnotations indexOfObject:annotation];
    if(index>=0 && index<_mapAnnotationValues.count){
        NSString *dirtyId = [AppUtils toString:_mapAnnotationValues[index]];
        WaterDirtyData *data = [self getWaterDataById:dirtyId];
        if([@"00" isEqualToString:data.position.status]){
            NSString *AnnotationViewID = @"AnimatedAnnotationWater";
            BMKAnnotationView *annotationView = (BMKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
            if (annotationView == nil) {
                annotationView = [[BMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
                [annotationView setBounds:CGRectMake(0.f, 0.f, 25.f, 25.f)];
                [annotationView setBackgroundColor:[UIColor clearColor]];
                annotationView.centerOffset = CGPointMake(0, 4);
                UIImageView *icon = [[UIImageView alloc] initWithFrame:annotationView.bounds];
                icon.image = [UIImage imageNamed:@"location_icon"];
                [annotationView addSubview:icon];
                annotationView.enabled = NO;
                icon.contentMode = UIViewContentModeScaleToFill;
                UILabel *label =[[UILabel alloc] initWithFrame:annotationView.bounds];
                label.textColor = [UIColor whiteColor];
                label.textAlignment = NSTextAlignmentCenter;
                label.font = [UIFont systemFontOfSize:12];
                label.tag = 101;
                label.userInteractionEnabled = YES;
                [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(animationClick:)]];
                [annotationView addSubview:label];
            }
            UILabel *l = [annotationView viewWithTag:101];
            l.accessibilityValue = dirtyId;
            l.text = [AppUtils toStr:data.index];
            return annotationView;
            
        }else{
            BOOL isDirect = data.position.isDirect;
            NSString *AnnotationViewID = @"AnimatedAnnotation";
            BMKAnnotationView *annotationView = (BMKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
            if (annotationView == nil) {
                annotationView = [[BMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
                [annotationView setBounds:CGRectMake(0.f, 0.f, 15.f, 15.f)];
                [annotationView setBackgroundColor:[UIColor clearColor]];
                UIImageView *icon = [[UIImageView alloc] initWithFrame:annotationView.bounds];
                icon.tag = 100;
                [annotationView addSubview:icon];
                icon.contentMode = UIViewContentModeScaleToFill;
            }
            UIImageView *icon = [annotationView viewWithTag:100];
            icon.image = [UIImage imageNamed: isDirect ? @"bad_water_river_yes":@"bad_water_river_no"];
            return annotationView;
        }
    }
    return nil;
}

// 地图区域即将改变时会调用此接口
- (void)mapView:(BMKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
    [self hideInput];
    [self hideTableView];
}

//地图区域改变完成后会调用此接口
- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    [self hideInput];
    [self hideTableView];
    BMKCoordinateRegion e=  mapView.region;
//    NSLog(@"%f---%f---\n%f---%f",e.center.longitude,e.center.latitude,e.span.longitudeDelta,e.span.latitudeDelta);
    [self locationMyPosition:e.center];
}

//点击水体坐标
-(void)animationClick:(UIGestureRecognizer *)recognize
{
    _currentDirtyId = recognize.view.accessibilityValue;
    WaterDirtyData *data = [self getWaterDataById:_currentDirtyId];
    if(data){
        [self initWaterInfoView:data];
    }
}

//设置界面
-(void)initWaterInfoView:(WaterDirtyData *)data
{
    _currentDirtyId = data.dirtyId;
    [_mapView setCenterCoordinate:[BMUtils getPoint:data.mapTag] animated:NO];
    _mapView.zoomLevel = DEFAULT_MAP_LEVEL;
    
//    NSString *directName =  data.position.isDirect ? @"污水0直排":@"非污水0直排";
    NSString *dirtyPlace = [AppUtils isEmpty:data.position.dirtyPlace]?@"":[NSString stringWithFormat:@"(%@)",data.position.dirtyPlace];
    _nameLabel.text = [NSString stringWithFormat:@"%@ %@",data.waterName,dirtyPlace];
    _typeLabel.text = [NSString stringWithFormat:@"%@类水质", data.wTypeName];
    _superviseBtn.hidden = ![LOGIN_USER canSuperView];

    [self showInfoview:YES];
    
}

-(void)hideInputWaterInfo
{
    [self showInfoview:NO];
    [self hideTableView];
}

-(void)hideTableView
{
    _linkTableView.hidden = YES;
    _linkTableViewH.constant = 0;
}

-(void)showInfoview:(BOOL)show
{
    if(show && _waterInfoView.hidden){
        _inforviewBottom.constant = -90;
        _waterInfoView.hidden = NO;
        _waterInfoView.top = MAIN_CONTENT_HEIGHT;
        [UIView animateWithDuration:0.3 animations:^{
            _waterInfoView.top = MAIN_CONTENT_HEIGHT-110;
        } completion:^(BOOL finished) {
            _inforviewBottom.constant = 20;
            _waterInfoView.hidden = NO;
        }];
    }else if(!show && !_waterInfoView.hidden){
        _inforviewBottom.constant = 20;
        _waterInfoView.top = MAIN_CONTENT_HEIGHT-110;
        [UIView animateWithDuration:0.15 animations:^{
            _waterInfoView.top = MAIN_CONTENT_HEIGHT;
        } completion:^(BOOL finished) {
            _inforviewBottom.constant = -90;
            _waterInfoView.hidden = YES;
        }];
    }
}

- (IBAction)superviseBtnClick:(UIButton *)sender
{
    WaterDirtyData *data = [self getWaterDataById:_currentDirtyId];
    if(data){
        SuperviseDetailViewController *controller= [[SuperviseDetailViewController alloc] init];
        controller.waterId = data.waterId;
        controller.recordId = nil;
        controller.waterName = data.waterName;
        [[AppUtils getNavigationController] pushViewController:controller animated:YES];
    }
}

- (IBAction)guideBtnClick:(UIButton *)sender
{
//    [self.navigationController pushViewController:[[PhoneGPSViewController alloc] initWithNibName:nil bundle:nil] animated:YES];
    
    
    WaterDirtyData *data = [self getWaterDataById:_currentDirtyId];
    if(data.index %2){
        [BMUtils openMapDrivingRoute:_locService.userLocation.location.coordinate endLocation:[BMUtils getPoint:data.mapTag] endName:data.waterName];
        
    }else{
        [BMUtils openNativeNavi:_locService.userLocation.location.coordinate endLocation:[BMUtils getPoint:data.mapTag]  endName:data.waterName];
    }

//    if (![self checkServicesInited])
//    {
//        return;
//    }
//    [self startNavi:_locService.userLocation.location.coordinate endLocation:[BMUtils getPoint:data.mapTag]  endName:data.waterName];

}

//#pragma mark ----------------[导航相关]------------------------
//
//- (void)startNavi:(CLLocationCoordinate2D)startLocation endLocation:(CLLocationCoordinate2D)endLocation endName:(NSString *)endName
//{
//    BOOL useMyLocation = YES;
//    NSMutableArray *nodesArray = [[NSMutableArray alloc]initWithCapacity:2];
//    //起点 传入的是原始的经纬度坐标，若使用的是百度地图坐标，可以使用BNTools类进行坐标转化
//    CLLocationCoordinate2D myLocation = [BMUtils getMyLocation];
//    BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init];
//    startNode.pos = [[BNPosition alloc] init];
//    if (useMyLocation) {
//        startNode.pos.x = myLocation.longitude;
//        startNode.pos.y = myLocation.latitude;
//        startNode.pos.eType = BNCoordinate_OriginalGPS;
//    }
//    else {
//        startNode.pos.x = startLocation.longitude;
//        startNode.pos.y = startLocation.latitude;
//        startNode.pos.eType = BNCoordinate_BaiduMapSDK;
//    }
//    [nodesArray addObject:startNode];
//    
//    //终点
//    BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];
//    endNode.pos = [[BNPosition alloc] init];
//    endNode.pos.x = endLocation.longitude;
//    endNode.pos.y = endLocation.latitude;
//    endNode.pos.eType = BNCoordinate_BaiduMapSDK;
//    [nodesArray addObject:endNode];
//    
//    //关闭openURL,不想跳转百度地图可以设为YES
//    BOOL isInishal = [BMUtils hasinitialMapApp];
//    [BNCoreServices_RoutePlan setDisableOpenUrl:YES];
//    [BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:nil];
//}
//
//#pragma mark - BNNaviRoutePlanDelegate
////算路成功回调
//-(void)routePlanDidFinished:(NSDictionary *)userInfo
//{
//    NSLog(@"算路成功");
//    
//    //路径规划成功，开始导航
//    [BNCoreServices_UI showPage:BNaviUI_NormalNavi delegate:self extParams:nil];
//    //导航中改变终点方法示例
//    /*dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//     BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];
//     endNode.pos = [[BNPosition alloc] init];
//     endNode.pos.x = 114.189863;
//     endNode.pos.y = 22.546236;
//     endNode.pos.eType = BNCoordinate_BaiduMapSDK;
//     [[BNaviModel getInstance] resetNaviEndPoint:endNode];
//     });*/
//}
//
////算路失败回调
//- (void)routePlanDidFailedWithError:(NSError *)error andUserInfo:(NSDictionary*)userInfo
//{
//    switch ([error code]%10000)
//    {
//        case BNAVI_ROUTEPLAN_ERROR_LOCATIONFAILED:
//            NSLog(@"暂时无法获取您的位置,请稍后重试");
//            break;
//        case BNAVI_ROUTEPLAN_ERROR_ROUTEPLANFAILED:
//            NSLog(@"无法发起导航");
//            break;
//        case BNAVI_ROUTEPLAN_ERROR_LOCATIONSERVICECLOSED:
//            NSLog(@"定位服务未开启,请到系统设置中打开定位服务。");
//            break;
//        case BNAVI_ROUTEPLAN_ERROR_NODESTOONEAR:
//            NSLog(@"起终点距离起终点太近");
//            break;
//        default:
//            NSLog(@"路径规划失败");
//            break;
//    }
//}
//
////算路取消回调
//-(void)routePlanDidUserCanceled:(NSDictionary*)userInfo {
//    NSLog(@"算路取消");
//}
//
//
////安静退出导航
//- (void)exitNaviUI
//{
//    [BNCoreServices_UI exitPage:EN_BNavi_ExitTopVC animated:YES extraInfo:nil];
//}
//
////BNNaviUIManagerDelegate
////退出导航页面回调
//- (void)onExitPage:(BNaviUIType)pageType  extraInfo:(NSDictionary*)extraInfo
//{
//    if (pageType == BNaviUI_NormalNavi)
//    {
//        NSLog(@"退出导航");
//    }
//    else if (pageType == BNaviUI_Declaration)
//    {
//        NSLog(@"退出导航声明页面");
//    }
//}
//
//- (BOOL)checkServicesInited
//{
//    if(![BNCoreServices_Instance isServicesInited])
//    {
//        [self showAlertWithTitle:@"提示" message:@"引擎尚未初始化完成，请稍后再试" cancelBottonTitle:@"我知道了" otherButtonTitle:nil clickBlock:^(NSInteger buttonIndex) {
//        }];
//        return NO;
//    }
//    return YES;
//}
//

@end
